package com.smag.web.controller.farming.mall;

import com.smag.common.core.domain.AjaxResult;
import com.smag.system.domain.FarmOrderAddress;
import com.smag.common.utils.SecurityUtils;
import com.smag.system.domain.dto.AddProductOrderDto;
import com.smag.system.service.FarmOrderAddressService;
import com.smag.system.service.FarmOrderProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/farming/mall/order")
public class OrderController {
    @Resource
    private FarmOrderAddressService farmOrderAddressService;
    @Resource
    private FarmOrderProductService farmOrderProductService;
    @GetMapping("/getUserAddress")
    public AjaxResult getUserAddress(){
        return farmOrderAddressService.getUserAddress(SecurityUtils.getUserId());
    }


    @PostMapping("/addUserAddress")
    public AjaxResult addUserAddress(@RequestBody FarmOrderAddress farmOrderAddress){
        farmOrderAddress.setUserId(SecurityUtils.getUserId());
        return farmOrderAddressService.addUserAddress(farmOrderAddress);
    }

    @PostMapping("/addProductOrder")
    public AjaxResult addProductOrder(@RequestBody AddProductOrderDto addProductOrderDto){
        Long userId = SecurityUtils.getUserId();
        return farmOrderProductService.addProductOrder(userId,addProductOrderDto);
    }
    @GetMapping
    public AjaxResult listOrders(){
        return farmOrderProductService.listOrders(SecurityUtils.getUserId());
    }

    @PutMapping("/payOrder")
    public AjaxResult payOrder(@RequestBody Long orderId){
        return farmOrderProductService.payOrder(orderId);
    }
}
